---
title: Groq
---

## Installation

```package-install
npm i llamaindex @llamaindex/groq
```

## Usage

First, create an API key at the [Groq Console](https://console.groq.com/keys). Then save it in your environment:

```bash
export GROQ_API_KEY=<your-api-key>
```

The initialize the Groq module.

```ts
import { Groq } from "@llamaindex/groq";
import { Settings } from "llamaindex";

Settings.llm = new Groq({
  // If you do not wish to set your API key in the environment, you may
  // configure your API key when you initialize the Groq class.
  // apiKey: "<your-api-key>",
});
```

## Load and index documents

For this example, we will use a single document. In a real-world scenario, you would have multiple documents to index.

```ts
import { Document, VectorStoreIndex } from "llamaindex";

const document = new Document({ text: essay, id_: "essay" });

const index = await VectorStoreIndex.fromDocuments([document]);
```

## Query

```ts
const queryEngine = index.asQueryEngine();

const query = "What is the meaning of life?";

const results = await queryEngine.query({
  query,
});
```

## Full Example

<include cwd>../../examples/groq.ts</include>

## API Reference

- [Groq](/docs/api/classes/Groq)
